package cn.seapon.talker.listener;

import android.support.v4.view.ViewPager.OnPageChangeListener;
import cn.seapon.talker.ChatActivity;
import cn.seapon.talker.R;
/**
 * 当ViewPager翻页时监听
 * @author daobo.yuan
 *
 */
public class MyOnPageChangeListener implements OnPageChangeListener{


	@Override
	public void onPageSelected(int arg0) {
		updateSelectedIndex(arg0);
	}
	
	/**
	 * 更新当前ViewPager索引
	 * @param currentSelectIndex
	 */
	private void updateSelectedIndex(int currentSelectIndex){
		if(null != ChatActivity.context){
			for (int i = 0; i < ChatActivity.context.expression_box.getChildCount(); i++) {
				if(currentSelectIndex == i){
					ChatActivity.context.expression_box.getChildAt(i).
											setBackgroundResource(R.drawable.page_focused);
				}else{
					ChatActivity.context.expression_box.getChildAt(i).
											setBackgroundResource(R.drawable.page_unfocused);
				}
			}
		}
	}
	
	@Override
	public void onPageScrollStateChanged(int arg0) {
	}
	@Override
	public void onPageScrolled(int arg0, float arg1, int arg2) {
	}
}
